package Argenti;

public class MyFunctions {
    private int variable;

    public MyFunctions() {
        variable = 1;
    }

    public MyFunctions(int i) {
        variable = i;
    }

    public long factorialIter() throws Exception {
        int x = 1;
        if (variable < 0) throw new Exception("Факториал отрицательного числа.");
        if (variable == 0) return 1;
        for (int i=1; i<=variable; i++) x *= i;
        return x;
    }
    
    public long factorialRec() {
        return factorialRec2(variable);
    }

    private long factorialRec2(long arg) {
        if (arg>0) {
            long rezult = factorialRec2(arg-1);
            System.out.println(rezult);
            if ((rezult == 0) || (rezult == 1./0)) {
                System.out.println("Переполнение!");
                System.exit(0);
            }
            return rezult*arg;
        }
        else return 1;
    }

    public double doubleFunction() {
        return (double)(variable+10)/4;
    }
}